home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Graphics Programming (2nd Edition)
/
Visual Basic Graphics Programming 2nd Edition.iso
/
OldSrc
/
CH10
/
SRC
/
ARCTAN2.BAS
next >
Wrap
BASIC Source File
|
1996-03-22
|
619b
|
28 lines
Attribute VB_Name = "AtcTan"
Option Explicit
' ************************************************
' Return the arc tangent of y/x taking into
' account the proper quadrant.
' ************************************************
Function Arctan2(x As Single, y As Single)
Const PI = 3.14159
Const PI_OVER_2 = PI / 2
Dim theta As Single
If x = 0 Then
If y > 0 Then
Arctan2 = PI_OVER_2
Else
Arctan2 = -PI_OVER_2
End If
Else
theta = Atn(y / x)
If x < 0 Then theta = PI + theta
Arctan2 = theta
End If
End Function